package com.wen.task.baseTasks;

import com.wen.entry.Result;
import com.wen.moudle.Account;
import com.wen.moudle.Managers.FightManager;
import com.wen.task.AbstractTask;
import lombok.extern.slf4j.Slf4j;

// 自动打天梯
@Slf4j
public class LadderTask extends AbstractTask {

    private FightManager fightManager;

    public LadderTask(Account account) {
        super(account);
        fightManager = getFightManager();
    }

    @Override
    public String getTitle() {
        return "一键打天梯";
    }

    @Override
    public void run() {
        Result<String> trophy = fightManager.getTrophy();
        log.info("{}", trophy.isSuccess() ? trophy.getData() : trophy.getErrorMessage());
        log.info("开始天梯战斗,请等待");
        Result<String> result =  fightManager.ladder();
        int count = 0;
        while (result.isSuccess()||result.getErrorMessage().contains("频繁")){
            result =  fightManager.ladder();
            log.info("正在进行第 {} 场天梯战斗！",++count);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        log.info("{}, 退出天梯战斗！",result.getErrorMessage());
    }
}
